#include "Explosion.h"
#include "../Game/Level.h"
#include "../Graphic/GraphicManager.h"
#include "../Graphic/TextureManager.h"
#include <vector>
#include <math.h>

//Update Explosion position
void cExplosion::Update(float lfTimeStep)
{
  mfElapsedTime += fabs(lfTimeStep );
  if (mfElapsedTime < 0.0525) return;
  mfElapsedTime = 0.0f;

  muiCurrentFrame = (muiCurrentFrame + 1);

  if (muiCurrentFrame > 8 )
    cLevel::Get().RemoveObject(macName);
}

//Render the current
void  cExplosion::Render()
{
 //Get game graphic properties 
  int miTileWidth = cGraphicManager::Get().GetTileWidth(); 
  int miTileHeight = cGraphicManager::Get().GetTileHeight(); 
  unsigned int luiXScreenOffset = cGraphicManager::Get().GetXScreenOffset(); 
  unsigned int luiYScreenOffset = cGraphicManager::Get().GetYScreenOffset(); 
  unsigned int luiGameHeight = cGraphicManager::Get().GetGameHeight(); 

  //Draw the explosion 
  cTexture lTexture = cTextureManager::Get().GetTexture("Data/Explosion.png"); 
  int tex1=lTexture.GetID(); 
  glEnable(GL_TEXTURE_2D); 
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
  glBindTexture(GL_TEXTURE_2D, tex1);   
  glColor3f(1.0,1.0,1.0); 
 
  float coordx_tile = 0.0f; 
  float coordy_tile = 0.0f; 
 
  coordx_tile = muiCurrentFrame * 0.125f;
  coordy_tile = 0.0f;

  double cteX = 0.09375f;
  double cteY = 0.75f;
 
  glBegin(GL_QUADS);     
    glTexCoord2f(coordx_tile, coordy_tile+cteY);	 
    glVertex2i(muiX*miTileWidth, muiY*miTileHeight); 
	  glTexCoord2f(coordx_tile+cteX, coordy_tile+cteY);	 
    glVertex2i((muiX+1)*miTileWidth , muiY*miTileHeight); 
	  glTexCoord2f(coordx_tile+cteX, coordy_tile);	 
    glVertex2i((muiX+1)*miTileWidth, (muiY+1)*miTileHeight); 
	  glTexCoord2f(coordx_tile, coordy_tile);	 
    glVertex2i(muiX*miTileWidth , (muiY+1)*miTileHeight); 
  glEnd();  
}
